package com.zhike.service.im.session;

import com.zhike.common.constant.RedisKey;
import com.zhike.common.utils.ServerSession;
import com.zhike.common.utils.ServerSessionMap;
import com.zhike.mobileimsdk.server.utils.RedisIns;

import io.netty.channel.Channel;

public class SessionUtil {
    /**
     * 清空当前节点uid的会话和集群中的会话，并关闭当前channel
     *
     * @param jedis
     * @param uid
     */
    public static void clearUserSessionAndCloseChannel(String uid) {
        // 删除本地会话
        ServerSession session = ServerSessionMap.getSession(uid);
        if (session != null) {
            Channel ch = session.getChannel();
            if (ch != null) {
                ch.close();
            }
        }
        ServerSessionMap.removeSession(uid);
        // 删除集群会话
        RedisIns.getInstance().getRedisIns().del(RedisKey.sessionStore(uid));
    }
}
